package cn.com.nthotline.json;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.text.TextUtils;
import cn.com.nthotline.model.ApplyJob;
import cn.com.nthotline.model.Area;
import cn.com.nthotline.model.Category;
import cn.com.nthotline.model.ComInfo;
import cn.com.nthotline.model.EduInfo;
import cn.com.nthotline.model.ExtraInfo;
import cn.com.nthotline.model.Favorite;
import cn.com.nthotline.model.Information;
import cn.com.nthotline.model.Interview;
import cn.com.nthotline.model.ListInfo;
import cn.com.nthotline.model.LoginState;
import cn.com.nthotline.model.RegisterState;
import cn.com.nthotline.model.ResumeDown;
import cn.com.nthotline.model.ResumeInfo;
import cn.com.nthotline.model.SubCategory;
import cn.com.nthotline.model.User;
import cn.com.nthotline.model.UserNotice;
import cn.com.nthotline.model.WorkInfo;

public class JsonParserImpl implements JsonPaserInterf {

	@Override
	public LoginState parserLoginData(String json) {
		// TODO Auto-generated method stub
		LoginState login = null;
		try {
			if (!TextUtils.isEmpty(json)) {
				JSONArray array = new JSONArray(json);
				JSONObject obj = array.getJSONObject(0);
				login = new LoginState();
				if (obj.getString(LoginState.STATUS).equals("1")) {
					login.setStatus(obj.getString(LoginState.STATUS));
					login.setType(obj.getString(LoginState.TYPE_ID));
					login.setMsg(obj.getString(LoginState.MSG));
				} else {
					login.setStatus(obj.getString(LoginState.STATUS));
					login.setMsg(obj.getString(LoginState.MSG));
				}
			}

		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return login == null ? null : login;
	}

	@Override
	public RegisterState parserRegisterData(String json) {
		// TODO Auto-generated method stub
		RegisterState register = null;
		try {
			if (!TextUtils.isEmpty(json)) {
				JSONArray array = new JSONArray(json);
				JSONObject obj = array.getJSONObject(0);
				register = new RegisterState();
				register.setStatus(obj.getString(RegisterState.STATUS));
				register.setMsg(obj.getString(RegisterState.MSG));
			}

		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return register == null ? null : register;
	}

	@Override
	public List<Information> parserInfoData(JSONArray array) {
		// TODO Auto-generated method stub
		List<Information> list = new ArrayList<Information>();
		try {
			if (array != null && array.length() > 0) {
				int size = array.length();
				for (int i = 0; i < size; i++) {
					JSONObject obj = array.getJSONObject(i);
					Information info = new Information();
					if (obj.has(Information.ID)) {
						info.setAreaId(obj.getString(Information.AREA_ID));
						info.setCatId(obj.getString(Information.CAT_ID));
						info.setContactWho(obj.getString(Information.CONTACT_WHO));
						info.setContent(obj.getString(Information.CONTENT));
						info.setId(obj.getString(Information.ID));
						info.setMail(obj.getString(Information.EMAIL));
						info.setQq(obj.getString(Information.QQ));
						info.setTel(obj.getString(Information.TEL));
						info.setTitle(obj.getString(Information.TITLE));
						if (obj.has(Information.CONTENT)) {
							info.setContent(obj.getString(Information.CONTENT));
						}
						info.setUserId(obj.getString(Information.USER_ID));
						// if(!TextUtils.isEmpty(obj.getString(Information.REFLESH_TIME))){
						info.setAddDate(obj.getString(Information.BEGIN_TIME));
						info.setReflesh(obj.getString(Information.REFLESH_TIME));
						// }else{
						// info.setAddDate(obj.getString(Information.BEGIN_TIME));
						// }
						list.add(info);
					}

				}
			}
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return list;
	}

	@Override
	public List<ExtraInfo> parserExtraInfoData(JSONArray array) {
		// TODO Auto-generated method stub
		List<ExtraInfo> list = new ArrayList<ExtraInfo>();
		try {
			if (array != null && array.length() > 0) {
				int size = array.length();
				for (int i = 0; i < size; i++) {
					JSONObject obj = array.getJSONObject(i);
					ExtraInfo info = new ExtraInfo();
					if (obj.has(ExtraInfo.TITLE) && !obj.getString(ExtraInfo.TITLE).equals("") && !obj.getString(ExtraInfo.VALUE).matches("^\\s*$")) {
						info.title = obj.getString(ExtraInfo.TITLE);
						info.value = obj.getString(ExtraInfo.VALUE);
						list.add(info);
						System.out.println(info);
					}
				}
			}
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return list;
	}

	@Override
	public List<Category> parserCategoryData(JSONArray array) {
		// TODO Auto-generated method stub
		List<Category> list = new ArrayList<Category>();
		try {
			if (array != null && array.length() > 0) {
				int size = array.length();
				for (int i = 0; i < size; i++) {
					JSONObject obj = array.getJSONObject(i);
					Category category = new Category();
					if (obj.has(Category.CAT_ID)) {

						category.setCatId(obj.getString(Category.CAT_ID));
						category.setCatName(obj.getString(Category.CAT_NAME));
						category.setDescription(obj
								.getString(Category.DESCRIPTION));
						category.setKeyWords(obj.getString(Category.KEYWORDS));
						if (obj.has(Category.PARENT_ID)) {
							category.setParentId(obj
									.getString(Category.PARENT_ID));
						}
						category.setTitle(obj.getString(Category.TITLE));
						list.add(category);
					}

				}
			}
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return list;
	}

	@Override
	public User parserUserData(String json) {
		// TODO Auto-generated method stub
		User user = null;
		try {
			if (!TextUtils.isEmpty(json)) {
				JSONArray array = new JSONArray(json);
				JSONObject obj = array.getJSONObject(0);
				user = new User();
				user.id = obj.getString(User.ID);
				user.userId = obj.getString(User.USERID);
				user.name = obj.getString(User.NAME);
				user.credit = obj.getString(User.CREDIT);
				user.mobile = obj.getString(User.MOBILE);
			}

		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return user == null ? null : user;
	}

	@Override
	public List<SubCategory> parserSubCategoryData(JSONArray array) {
		// TODO Auto-generated method stub
		List<SubCategory> list = new ArrayList<SubCategory>();
		try {
			if (array != null && array.length() > 0) {
				int size = array.length();
				for (int i = 0; i < size; i++) {
					JSONObject obj = array.getJSONObject(i);
					SubCategory category = new SubCategory();
					if (obj.has(SubCategory.ID)) {
						category.id = obj.getString(SubCategory.ID);
						category.catId = obj.getString(SubCategory.CATID);
						category.catName = obj.getString(SubCategory.CATNAME);
						category.descrpt = obj.getString(SubCategory.DESCRPT);
						category.keyWords = obj.getString(SubCategory.KEYWORDS);
						category.title = obj.getString(SubCategory.TITLE);
						list.add(category);
					}

				}
			}
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return list;
	}

	@Override
	public List<Area> parserAreaData(JSONArray array) {
		// TODO Auto-generated method stub
		List<Area> list = new ArrayList<Area>();
		try {
			if (array != null && array.length() > 0) {
				int size = array.length();
				for (int i = 0; i < size; i++) {
					JSONObject obj = array.getJSONObject(i);
					Area area = new Area();
					if (obj.has(Area.ID)) {
						area.areaId = obj.getString(Area.ID);
						area.areaName = obj.getString(Area.NAME);
						area.parentId = obj.getString(Area.PARENTID);
						list.add(area);
					}
				}
			}
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return list;
	}

	@Override
	public List<Favorite> parserFavData(JSONArray array) {
		// TODO Auto-generated method stub
		List<Favorite> list = new ArrayList<Favorite>();
		try {
			if (array != null && array.length() > 0) {
				int size = array.length();
				for (int i = 0; i < size; i++) {
					JSONObject obj = array.getJSONObject(i);
					Favorite fav = new Favorite();
					if (obj.has(Favorite.ID)) {
						fav.id = obj.getString(Favorite.ID);
						fav.addTime = obj.getString(Favorite.ADDTIME);
						fav.beginTime = obj.getString(Favorite.BEGINTIME);
						fav.conetnt = obj.getString(Favorite.CONTENT);
						fav.title = obj.getString(Favorite.TITLE);
						fav.userId = obj.getString(Favorite.USERID);
						list.add(fav);
					}
				}
			}
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return list;
	}

	@Override
	public List<ListInfo> parserListInfoData(JSONArray array) {
		// TODO Auto-generated method stub
		List<ListInfo> list = new ArrayList<ListInfo>();
		try {
			if (array != null && array.length() > 0) {
				int size = array.length();
				for (int i = 0; i < size; i++) {
					JSONObject obj = array.getJSONObject(i);
					ListInfo info = new ListInfo();
					if (obj.has(ListInfo.ID)) {
						info.id = obj.getString(ListInfo.ID);
						info.beginTime = obj.getString(ListInfo.BEGINTIME);
						info.content = obj.getString(ListInfo.CONTENT);
						info.title = obj.getString(ListInfo.TITLE);
						info.userId = obj.getString(ListInfo.USERID);
						info.hit = obj.getString(ListInfo.HIT);
						info.imgPath = obj.getString(ListInfo.IMG_PATH);
						info.activeTime = obj.getString(ListInfo.ACTIVETIME);
						info.areaId = obj.getString(ListInfo.AREAID);
						info.catId = obj.getString(ListInfo.CATID);
						info.contactWho = obj.getString(ListInfo.CONTACT_WHO);
						info.email = obj.getString(ListInfo.EMAIL);
						info.endTime = obj.getString(ListInfo.ENDTIME);
						info.qq = obj.getString(ListInfo.QQ);
						info.refreshTime = obj.getString(ListInfo.REFRESHTIME);
						info.subcateid = obj.getString(ListInfo.SUBCATEID);
						list.add(info);
					}
				}
			}
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return list;
	}

	@Override
	public List<ResumeInfo> parserResumeList(JSONArray array) {
		// TODO Auto-generated method stub
		List<ResumeInfo> list = new ArrayList<ResumeInfo>();
		try {
			if (array != null && array.length() > 0) {
				int size = array.length();
				for (int i = 0; i < size; i++) {
					JSONObject obj = array.getJSONObject(i);
					ResumeInfo info = new ResumeInfo();
					if (obj.has(ResumeInfo.ID)) {
						info.uid = obj.getString(ResumeInfo.UID);
						info.address = obj.getString(ResumeInfo.ADDRESS);
						info.houseAddress = obj
								.getString(ResumeInfo.HOUSE_ADDRESS);
						info.birth = obj.getString(ResumeInfo.BIRTH);
						info.district = obj.getString(ResumeInfo.DISTRIT);
						info.education = obj.getString(ResumeInfo.EDUCATION);
						info.experience = obj.getString(ResumeInfo.EXPERIENCE);
						info.fullName = obj.getString(ResumeInfo.FULL_NAME);
						info.id = obj.getString(ResumeInfo.ID);
						info.intentionJobs = obj
								.getString(ResumeInfo.INTENTIONJOB);
						info.nature = obj.getString(ResumeInfo.NATURE);
						info.refreshTime = obj
								.getString(ResumeInfo.REFRESHTIME);
						info.addTime = obj.getString(ResumeInfo.ADDTIME);
						info.sex = obj.getString(ResumeInfo.SEX);
						info.specialty = obj.getString(ResumeInfo.SPECAILTY);
						info.wage = obj.getString(ResumeInfo.WAGE);
						info.tel = obj.getString(ResumeInfo.TEL);
						info.title = obj.getString(ResumeInfo.TITLE);
						info.trade = obj.getString(ResumeInfo.TRADE);
						info.email = obj.getString(ResumeInfo.EMAIL);
						list.add(info);
					}
				}
			}
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return list;
	}

	@Override
	public List<WorkInfo> parserWorkInfo(JSONArray array) {
		// TODO Auto-generated method stub
		List<WorkInfo> list = new ArrayList<WorkInfo>();
		try {
			if (array != null && array.length() > 0) {
				int size = array.length();
				for (int i = 0; i < size; i++) {
					JSONObject obj = array.getJSONObject(i);
					WorkInfo info = new WorkInfo();
					if (obj.has(WorkInfo.ID)) {

						info.id = obj.getString(WorkInfo.ID);
						info.pid = obj.getString(WorkInfo.PID);
						info.uid = obj.getString(WorkInfo.UID);
						info.start = obj.getString(WorkInfo.START);
						info.end = obj.getString(WorkInfo.END);
						info.company = obj.getString(WorkInfo.COMPANY);
						info.jobs = obj.getString(WorkInfo.JOB);
						info.achievements = obj
								.getString(WorkInfo.ACHIEVEMENTS);
						list.add(info);
					}
				}
			}
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return list;
	}

	@Override
	public List<EduInfo> parserEduInfo(JSONArray array) {
		// TODO Auto-generated method stub
		List<EduInfo> list = new ArrayList<EduInfo>();
		try {
			if (array != null && array.length() > 0) {
				int size = array.length();
				for (int i = 0; i < size; i++) {
					JSONObject obj = array.getJSONObject(i);
					EduInfo info = new EduInfo();
					if (obj.has(EduInfo.ID)) {

						info.id = obj.getString(EduInfo.ID);
						info.pid = obj.getString(EduInfo.PID);
						info.uid = obj.getString(EduInfo.UID);
						info.start = obj.getString(EduInfo.START);
						info.end = obj.getString(EduInfo.END);
						info.school = obj.getString(EduInfo.SCHOOL);
						info.speciality = obj.getString(EduInfo.SPECIALITY);
						list.add(info);
					}
				}
			}
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return list;
	}

	@Override
	public List<Interview> parserInterviewInfo(JSONArray array) {
		// TODO Auto-generated method stub
		List<Interview> list = new ArrayList<Interview>();
		try {
			if (array != null && array.length() > 0) {
				int size = array.length();
				for (int i = 0; i < size; i++) {
					JSONObject obj = array.getJSONObject(i);
					Interview interview = new Interview();
					if (obj.has(Interview.ID)) {

						interview.id = obj.getString(Interview.ID);
						interview.resumeId = obj.getString(Interview.RESUME_ID);
						interview.resumeName = obj
								.getString(Interview.RESUME_NAME);
						interview.resumeUid = obj
								.getString(Interview.RESUME_UID);
						interview.jobId = obj.getString(Interview.JOBS_ID);
						interview.jobName = obj.getString(Interview.JOBS_NAME);
						interview.comId = obj.getString(Interview.COMPANY_ID);
						interview.comName = obj
								.getString(Interview.COMPANY_NAME);
						interview.comUid = obj.getString(Interview.COMPANY_UID);
						interview.interviewAddTime = obj
								.getString(Interview.INTERVIEW_ADDTIME);
						list.add(interview);
					}
				}
			}
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return list;
	}

	@Override
	public List<ResumeDown> parserResumeDownInfo(JSONArray array) {
		// TODO Auto-generated method stub
		List<ResumeDown> list = new ArrayList<ResumeDown>();
		try {
			if (array != null && array.length() > 0) {
				int size = array.length();
				for (int i = 0; i < size; i++) {
					JSONObject obj = array.getJSONObject(i);
					ResumeDown down = new ResumeDown();
					if (obj.has(ResumeDown.ID)) {

						down.id = obj.getString(ResumeDown.ID);
						down.resumeId = obj.getString(ResumeDown.RESUME_ID);
						down.resumeName = obj.getString(ResumeDown.RESUME_NAME);
						down.resumeUid = obj.getString(ResumeDown.RESUME_UID);
						down.comName = obj.getString(ResumeDown.COMPANY_NAME);
						down.comUid = obj.getString(ResumeDown.COMPANY_UID);
						down.downAddTime = obj
								.getString(ResumeDown.DOWN_ADDTIME);
						list.add(down);
					}
				}
			}
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return list;
	}

	@Override
	public List<ApplyJob> parserApplyJobInfo(JSONArray array) {
		// TODO Auto-generated method stub
		List<ApplyJob> list = new ArrayList<ApplyJob>();
		try {
			if (array != null && array.length() > 0) {
				int size = array.length();
				for (int i = 0; i < size; i++) {
					JSONObject obj = array.getJSONObject(i);
					ApplyJob job = new ApplyJob();
					if (obj.has(ApplyJob.ID)) {

						job.id = obj.getString(ApplyJob.ID);
						job.resumeId = obj.getString(ApplyJob.RESUME_ID);
						job.resumeName = obj.getString(ApplyJob.RESUME_NAME);
						job.comId = obj.getString(ApplyJob.COMPANY_ID);
						job.comName = obj.getString(ApplyJob.COMPANY_NAME);
						job.comUid = obj.getString(ApplyJob.COMPANY_UID);
						job.applyAddtime = obj
								.getString(ApplyJob.APPLY_ADDTIME);
						job.jobId = obj.getString(ApplyJob.JOBS_ID);
						job.jobName = obj.getString(ApplyJob.JOBS_NAME);
						job.personUid = obj.getString(ApplyJob.PERSON_UID);
						list.add(job);
					}
				}
			}
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return list;

	}

	@Override
	public List<UserNotice> parserUserNoticeData(JSONArray array) {
		// TODO Auto-generated method stub
		List<UserNotice> list = new ArrayList<UserNotice>();
		try {
			if (array != null && array.length() > 0) {
				int size = array.length();
				for (int i = 0; i < size; i++) {
					JSONObject obj = array.getJSONObject(i);
					UserNotice notice = new UserNotice();
					if (obj.has(UserNotice.ID)) {
						notice.id = obj.getString(UserNotice.ID);
						notice.content = obj.getString(UserNotice.CONTENT);
						notice.from = obj.getString(UserNotice.FROM);
						notice.time = obj.getString(UserNotice.PUBTIME);
						notice.title = obj.getString(UserNotice.TITLE);
						list.add(notice);
					}
				}
			}
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return list;
	}

	/**
	 * public String uid; public String jobName; public String comName; public
	 * String comId; public String nature; public String sex; public String
	 * category; public String trade; public String scale; public String
	 * district; public String edu; public String exper; public String wage;
	 * public String contents; public String addtime; public String refleshtime;
	 */
	@Override
	public List<ListInfo> parserQuanzhiInfoData(JSONArray array) {
		// TODO Auto-generated method stub
		List<ListInfo> list = new ArrayList<ListInfo>();
		try {
			if (array != null && array.length() > 0) {
				int size = array.length();
				for (int i = 0; i < size; i++) {
					JSONObject obj = array.getJSONObject(i);
					ListInfo info = new ListInfo();
					if (obj.has(ListInfo.ID)) {
						info.id = obj.getString(ListInfo.ID);
						info.uid = obj.getString(ListInfo.UID);
						info.jobName = obj.getString(ListInfo.JOB_NAME);
						info.comName = obj.getString(ListInfo.COM_NAME);
						info.comId = obj.getString(ListInfo.COM_ID);
						info.nature = obj.getString(ListInfo.NATURE);
						info.sex = obj.getString(ListInfo.SEX);
						info.category = obj.getString(ListInfo.CATEGORY);
						info.trade = obj.getString(ListInfo.TRADE);
						info.scale = obj.getString(ListInfo.SCALE);
						info.district = obj.getString(ListInfo.DISTRICT);
						info.edu = obj.getString(ListInfo.EDU);
						info.exper = obj.getString(ListInfo.EXPER);
						info.wage = obj.getString(ListInfo.WAGE);
						info.addtime = obj.getString(ListInfo.ADDTIME);
						info.refreshTime = obj.getString(ListInfo.REFRESHTIME);
						info.contents = obj.getString(ListInfo.CONTENTS);
						info.amount = obj.getString(ListInfo.AMOUNT);
						list.add(info);
					}
				}
			}
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return list;
	}

	@Override
	public List<ComInfo> parserComInfoData(JSONArray array) {
		// TODO Auto-generated method stub
		List<ComInfo> list = new ArrayList<ComInfo>();
		try {
			if (array != null && array.length() > 0) {
				int size = array.length();
				for (int i = 0; i < size; i++) {
					JSONObject obj = array.getJSONObject(i);
					ComInfo info = new ComInfo();
					if (obj.has(ComInfo.ID)) {
						info.id = obj.getString(ComInfo.ID);
						info.address = obj.getString(ComInfo.ADDRESS);
						info.comName = obj.getString(ComInfo.COMNAME);
						info.contact = obj.getString(ComInfo.CONTACT);
						info.content = obj.getString(ComInfo.CONTENT);
						info.district = obj.getString(ComInfo.DISTRICT);
						info.email = obj.getString(ComInfo.EMAIL);
						info.nature = obj.getString(ComInfo.NATURE);
						info.scale = obj.getString(ComInfo.SCALE);
						info.tel = obj.getString(ComInfo.TEL);
						info.trade = obj.getString(ComInfo.TRADE);
						info.uid = obj.getString(ComInfo.UID);
						list.add(info);
					}
				}
			}
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return list;
	}

	@Override
	public List<ListInfo> parserSeekerData(JSONArray array) {
		// TODO Auto-generated method stub
		
		
		List<ListInfo> list = new ArrayList<ListInfo>();
		try {
			if (array != null && array.length() > 0) {
				int size = array.length();
				for (int i = 0; i < size; i++) {
					JSONObject obj = array.getJSONObject(i);
					ListInfo info = new ListInfo();
					if (obj.has(ListInfo.ID)) {
						info.id = obj.getString(ListInfo.ID);
						info.address = obj.getString(ListInfo.ADDRES);
						info.district = obj.getString(ListInfo.DISTRICT);
						info.email = obj.getString(ListInfo.EMAIL);
						info.nature = obj.getString(ListInfo.NATURE);
						info.telephone = obj.getString(ListInfo.TELE);
						info.trade = obj.getString(ListInfo.TRADE);
						info.uid = obj.getString(ListInfo.UID);
						info.addtime=obj.getString(ListInfo.ADDTIME);
						info.birth=obj.getString(ListInfo.BIRTH);
						info.education=obj.getString(ListInfo.EDUCATION);
						info.experience=obj.getString(ListInfo.EXPERIENCE);
						info.fullName=obj.getString(ListInfo.FULLNAME);
						info.height=obj.getString(ListInfo.HEIGHT);
						info.householdaddress=obj.getString(ListInfo.HOUSEHOLD);
						info.intentionJobs=obj.getString(ListInfo.INTENTIONJOB);
						info.marriage=obj.getString(ListInfo.MARRIAGE);
						info.refreshtime=obj.getString(ListInfo.REFRESHTIME);
						info.sex=obj.getString(ListInfo.SEX);
						info.specialty=obj.getString(ListInfo.SPECAILTY);
						info.wage=obj.getString(ListInfo.WAGE);
						list.add(info);
					}
				}
			}
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return list;
		
		
		
	}

}
